package com.iamteer.a_test_upload;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/upload")
public class UploadServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*
		request.getQueryString();	//获取 GET：username=Tom&pwd=888
		request.getInputStream();	//获取 POST：inputstream
		request.getParameter("");
		*/
		
		// 获取表单（POST）数据
		InputStream in = request.getInputStream();
		// 转换流
//		InputStreamReader inReader = new InputStreamReader(in,"gbk");
		InputStreamReader inReader = new InputStreamReader(in,"utf-8");
		// 缓冲流
		BufferedReader reader = new BufferedReader(inReader);
		
		String string = null;
		while ((string = reader.readLine()) != null) {
			System.out.println(string);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
